home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / fx / AsteroidD.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  9.1 KB  |  268 lines

  1. class classes.fx.AsteroidD
  2. {
  3.    var size;
  4.    var id;
  5.    var x;
  6.    var y;
  7.    var dir;
  8.    var power;
  9.    var clip;
  10.    var feeler;
  11.    var xMov;
  12.    var xMovT;
  13.    var yMov;
  14.    var yMovT;
  15.    var c = 0;
  16.    var sizeArray = [[1,3],[4,9],[10,17],[18,23],[24,27]];
  17.    var yank = false;
  18.    var feelerCount = 0;
  19.    var feelerBreak = false;
  20.    function AsteroidD(px, py, psize, pdir, pid)
  21.    {
  22.       this.size = psize;
  23.       this.id = pid;
  24.       this.x = px;
  25.       this.y = py;
  26.       this.dir = pdir;
  27.       this.power = this.size * 6;
  28.       _root.d = _root.d + 1;
  29.       this.clip = _root.attachMovie("asteroid","asteroidD" + this.id + "Clip",_root.d + 75000);
  30.       this.clip.body.gotoAndStop(_root.randRange(this.sizeArray[this.size - 1][0],this.sizeArray[this.size - 1][1]));
  31.       _root.d = _root.d + 1;
  32.       this.feeler = this.clip.attachMovie("asteroidDFeeler","asteroidDFeeler" + this.id,_root.d + 75000);
  33.       this.feeler._x = -100;
  34.       this.feeler._y = -100;
  35.       this.feeler._width = 50 + this.clip.body._width;
  36.       this.feeler._height = 50 + this.clip.body._height;
  37.       if(this.dir == "U")
  38.       {
  39.          this.xMov = this.xMovT = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  40.          this.yMov = this.yMovT = _root.randRange2(this.size - 9,0);
  41.       }
  42.       else if(this.dir == "D")
  43.       {
  44.          this.xMov = this.xMovT = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  45.          this.yMov = this.yMovT = _root.randRange2(0,-1 * (this.size - 9));
  46.       }
  47.       else if(this.dir == "L")
  48.       {
  49.          this.xMov = this.xMovT = _root.randRange2(this.size - 9,0);
  50.          this.yMov = this.yMovT = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  51.       }
  52.       else
  53.       {
  54.          this.xMov = this.xMovT = _root.randRange2(0,-1 * (this.size - 9));
  55.          this.yMov = this.yMovT = _root.randRange2(this.size - 9,-1 * (this.size - 9));
  56.       }
  57.       this.xMovT *= _root.dif.speed;
  58.       this.yMovT *= _root.dif.speed;
  59.       this.clip._x = this.x;
  60.       this.clip._y = this.y;
  61.       var _loc3_ = new flash.geom.Transform(this.clip);
  62.       var _loc4_ = new flash.geom.ColorTransform(0,0,0,1,-255,-255,-255,0);
  63.       _loc3_.colorTransform = _loc4_;
  64.       this.clip._rotation = random(4) * 90;
  65.    }
  66.    function bombed()
  67.    {
  68.       _root.createExploD([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  69.       this.yank = true;
  70.    }
  71.    function explode()
  72.    {
  73.       _root.createExploD([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  74.       var _loc6_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  75.       _root.audio.playLevel4("astX" + _loc6_ + "_" + (random(2) + 1),_root.randRange(25,45));
  76.       this.size -= 3;
  77.       if(this.size >= 1)
  78.       {
  79.          var _loc5_ = ["L","R","U","D"];
  80.          var _loc4_ = _root.randRange(2,3 + this.size);
  81.          var _loc3_ = 0;
  82.          while(_loc3_ < _loc4_)
  83.          {
  84.             _root.createAsteroidD([this.x,this.y,this.size,_loc5_[random(4)]]);
  85.             _loc3_ = _loc3_ + 1;
  86.          }
  87.       }
  88.       this.yank = true;
  89.    }
  90.    function stopMov()
  91.    {
  92.       this.xMovT = 0;
  93.       this.yMovT = 0;
  94.    }
  95.    function attack()
  96.    {
  97.       var _loc3_ = _root.getAngleRad2(this.x,this.y,_root[_root.char].x + 20,_root[_root.char].y + 20);
  98.       this.xMovT = Math.cos(_loc3_) * _root.randRange2(7,10);
  99.       this.yMovT = Math.sin(_loc3_) * _root.randRange2(7,10);
  100.       this.xMovT *= _root.dif.speed;
  101.       this.yMovT *= _root.dif.speed;
  102.    }
  103.    function main()
  104.    {
  105.       this.c = this.c + 1;
  106.       if(this.clip.body.hitTest(_root[_root.char + "Clip"]))
  107.       {
  108.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  109.          _root.createExploD([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  110.          var _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  111.          _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  112.          if(this.size > 2)
  113.          {
  114.             this.size -= 1;
  115.             var _loc4_ = _root.randRange(1,2);
  116.             var _loc3_ = 0;
  117.             while(_loc3_ < _loc4_)
  118.             {
  119.                _root.createAsteroidD([this.x,this.y,this.size,tempDir]);
  120.                _loc3_ = _loc3_ + 1;
  121.             }
  122.          }
  123.          this.yank = true;
  124.       }
  125.       _loc3_ = 0;
  126.       var _loc8_ = _root.broShots.length;
  127.       while(_loc3_ < _loc8_)
  128.       {
  129.          var _loc5_ = _root.broShots[_loc3_] + "Clip";
  130.          if(this.clip.body.hitTest(_root[_loc5_]))
  131.          {
  132.             _root.createExploD([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  133.             _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  134.             _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  135.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar - 1;
  136.             var _loc6_ = _root.broShots[_loc3_];
  137.             _root[_loc6_].exploX = this.x + this.clip.body._width / 2;
  138.             _root[_loc6_].exploY = this.y + this.clip.body._height / 2;
  139.             var tempDir = _root[_loc6_].dir;
  140.             _root[_loc6_].hit();
  141.             if(this.size > 2)
  142.             {
  143.                this.size -= 1;
  144.                _loc4_ = _root.randRange(1,2);
  145.                _loc3_ = 0;
  146.                while(_loc3_ < _loc4_)
  147.                {
  148.                   _root.createAsteroidD([this.x,this.y,this.size,tempDir]);
  149.                   _loc3_ = _loc3_ + 1;
  150.                }
  151.             }
  152.             this.yank = true;
  153.             break;
  154.          }
  155.          _loc3_ = _loc3_ + 1;
  156.       }
  157.       if(!_root.astField)
  158.       {
  159.          _loc3_ = 0;
  160.          _loc8_ = _root.enemyShots.length;
  161.          while(_loc3_ < _loc8_)
  162.          {
  163.             _loc5_ = _root.enemyShots[_loc3_] + "Clip";
  164.             if(this.clip.body.hitTest(_root[_loc5_]))
  165.             {
  166.                _root.createExploD([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  167.                _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  168.                _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  169.                _loc6_ = _root.enemyShots[_loc3_];
  170.                var tempDir = _root[_loc6_].dir;
  171.                _root[_loc6_].hit(this.size);
  172.                if(this.size > 2)
  173.                {
  174.                   this.size -= 1;
  175.                   _root.createAsteroidD([this.x,this.y,this.size,tempDir]);
  176.                }
  177.                this.yank = true;
  178.                break;
  179.             }
  180.             _loc3_ = _loc3_ + 1;
  181.          }
  182.          if(random(3) == 0)
  183.          {
  184.             _loc3_ = 0;
  185.             _loc8_ = _root.chars.length;
  186.             while(_loc3_ < _loc8_)
  187.             {
  188.                _loc5_ = _root.chars[_loc3_] + "Clip";
  189.                if(!this.feelerBreak)
  190.                {
  191.                   if(this.feeler.hitTest(_root[_loc5_]))
  192.                   {
  193.                      _loc6_ = _root.chars[_loc3_];
  194.                      _root[_loc6_].evade();
  195.                      this.feelerCount = 0;
  196.                      this.feelerBreak = true;
  197.                   }
  198.                }
  199.                if(this.clip.body.hitTest(_root[_loc5_]))
  200.                {
  201.                   _root.createExploD([this.x,this.y,this.size * 20 + 40,_root.randRange(75,100)]);
  202.                   _loc7_ = !(this.size == 2 || this.size == 4) ? this.size : this.size - 1;
  203.                   _root.audio.playLevel4("astX" + _loc7_ + "_" + (random(2) + 1),_root.randRange(25,45));
  204.                   _loc6_ = _root.chars[_loc3_];
  205.                   var tempDir = _root[_loc6_].dir;
  206.                   _root[_loc6_].bombed(this.power);
  207.                   if(this.size > 2)
  208.                   {
  209.                      this.size -= 1;
  210.                      _root.createAsteroidD([this.x,this.y,this.size,tempDir]);
  211.                   }
  212.                   this.yank = true;
  213.                   break;
  214.                }
  215.                _loc3_ = _loc3_ + 1;
  216.             }
  217.             if(this.feelerBreak)
  218.             {
  219.                this.feelerCount = this.feelerCount + 1;
  220.                if(this.feelerCount == 5)
  221.                {
  222.                   this.feelerBreak = false;
  223.                }
  224.             }
  225.          }
  226.       }
  227.       if(this.c > 100)
  228.       {
  229.          if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  230.          {
  231.             this.yank = true;
  232.          }
  233.       }
  234.       if(this.yank)
  235.       {
  236.          _root.removeFX("asteroidD" + this.id);
  237.       }
  238.       if(this.xMovT < this.xMov)
  239.       {
  240.          this.xMov -= 0.5;
  241.       }
  242.       else if(this.xMovT > this.xMov)
  243.       {
  244.          this.xMov += 0.5;
  245.       }
  246.       else
  247.       {
  248.          this.xMov = this.xMovT;
  249.       }
  250.       if(this.yMovT < this.yMov)
  251.       {
  252.          this.yMov -= 0.5;
  253.       }
  254.       else if(this.yMovT > this.yMov)
  255.       {
  256.          this.yMov += 0.5;
  257.       }
  258.       else
  259.       {
  260.          this.yMov = this.yMovT;
  261.       }
  262.       this.x += this.xMov;
  263.       this.y += this.yMov;
  264.       this.clip._x = this.x;
  265.       this.clip._y = this.y;
  266.    }
  267. }
  268.